package com.example.xinli.service.serviceImpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.xinli.dao.HuibidanganMapper;
import com.example.xinli.dao.JiazhishouceMapper;
import com.example.xinli.domain.entity.Huibidangan;
import com.example.xinli.domain.entity.Jiazhishouce;
import com.example.xinli.domain.vo.HuibidanganSubmitVo;
import com.example.xinli.domain.vo.JiazhishouceSubmitVo;
import com.example.xinli.domain.vo.ResponseBean;
import com.example.xinli.domain.vo.ResponseBeanEnum;
import com.example.xinli.service.IHuibidanganService;
import com.example.xinli.service.IJiazhishouceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class JiazhishouceServiceImpl extends ServiceImpl<JiazhishouceMapper, Jiazhishouce> implements IJiazhishouceService {

    @Autowired
    JiazhishouceMapper jiazhishouceMapper;

    @Override
    public ResponseBean getAllUserJiazhishouce(String userId) {
        QueryWrapper<Jiazhishouce> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", userId);
        List<Jiazhishouce> jiazhishouceList = jiazhishouceMapper.selectList(queryWrapper);
        return ResponseBean.success(jiazhishouceList);
    }

    @Override
    public ResponseBean submitJiazhishouce(JiazhishouceSubmitVo jiazhishouceSubmitVo) {
        Jiazhishouce jiazhishouce = new Jiazhishouce();
        jiazhishouce.setUserId(jiazhishouceSubmitVo.getUserId());
        jiazhishouce.setDate(jiazhishouceSubmitVo.getDate());
        jiazhishouce.setLingyu(jiazhishouceSubmitVo.getLingyu());
        jiazhishouce.setMiaoshu(jiazhishouceSubmitVo.getMiaoshu());
        jiazhishouce.setYitu(jiazhishouceSubmitVo.getYitu());
        jiazhishouce.setPingjia(jiazhishouceSubmitVo.getPingjia());
        jiazhishouce.setShiqing(jiazhishouceSubmitVo.getShiqing());
        jiazhishouce.setRecordId(-1);

        int res = jiazhishouceMapper.insert(jiazhishouce);
        if (res > 0) {
            return ResponseBean.success();
        }
        return ResponseBean.error(ResponseBeanEnum.ERROR);
    }
}

